/**
 * @author Klas
 */

var validering = {

    init: function () {
		
		var form = document.getElementById("regformularet");

        var Name = document.getElementById("name");
        var SureName = document.getElementById("surename");
        var eMail = document.getElementById ("email");
        var comment = document.getElementById ("comment");
		
     // Focusfunktionen
		// vid fokus visa tooltippet
        //Name
        Name.onfocus = function () {
            // skapa divtaggen
            var divTag = document.createElement("div");
            divTag.className = "tooltip";
            document.body.appendChild(divTag);

            var text = document.createTextNode("Ange ditt förnamn"); 
            divTag.appendChild(text);

            var pos = validering.findPos(this);
            divTag.style.left = pos[0] + 195 + "px";
            divTag.style.top = pos[1] + "px";

            // Ta bort Tooltippet (divtaggen)
            Name.onblur = function () {
                document.body.removeChild(divTag);
            };
        };
        
       SureName.onfocus = function () {
            // skapa divtaggen
            var divTag = document.createElement("div");
            divTag.className = "tooltip";
            document.body.appendChild(divTag);

            var text = document.createTextNode("Ange ditt efternamn"); 
            divTag.appendChild(text);

            var pos = validering.findPos(this);
            divTag.style.left = pos[0] + 195 + "px";
            divTag.style.top = pos[1] + "px";

            // Ta bort Tooltippet (divtaggen)
            SureName.onblur = function () {
                document.body.removeChild(divTag);
            };
        };
        
        //Email
         eMail.onfocus = function () {
            // skapa divtaggen
            var divTag = document.createElement("div");
            divTag.className = "tooltip";
            document.body.appendChild(divTag);

            var text = document.createTextNode("Viktigt! Ange en äkta E-postadress");
            divTag.appendChild(text);

            var pos = validering.findPos(this);
            divTag.style.left = pos[0] + 195 + "px";
            divTag.style.top = pos[1] + "px";

            // Ta bort divtaggen
            eMail.onblur = function () {
                document.body.removeChild(divTag);
            };
        };
               
         //Comment
        comment.onfocus = function () {
            // skapa divtaggen
            var divTag = document.createElement("div");
            divTag.className = "tooltip";
            document.body.appendChild(divTag);

            var text = document.createTextNode("Skriv vad Ni har på hjärtat...");
            divTag.appendChild(text);

            var pos = validering.findPos(this);
            divTag.style.left = pos[0] + 255 + "px";
            divTag.style.top = pos[1] + "px";

            // Ta bort divtaggen
            comment.onblur = function () {
                document.body.removeChild(divTag);
            };
        };
        
      },

    // funktion för att positionera tooltippet
    findPos: function (obj) {
        var curleft = curtop = 0;
        if (obj.offsetParent) {
            do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            }
            while (obj = obj.offsetParent);
            return [curleft, curtop];
        }
    }

};

window.onload = validering.init;